//
//账户注销 
window.addEventListener("DOMContentLoaded",function(){
    let btn_logout = document.querySelector('#btn_logout');

    //登录用户名
    let username = document.querySelector('#login_account').innerText;
    //注销
    btn_logout.addEventListener("click",function(){
        //
        //清除数据
        //

        //清除登录类型及用户名cookie
        removeCookie('type');
        //清除cookie 即未保存密码的cookie
        if (getCookie(username)=='') {
            removeCookie(username);
        }
        //跳转登录
        location.replace('login.html')
    });



    //删除cookie
    function removeCookie(name){
        var i=document.cookie.indexOf(name);
        let val;
        if(i!=-1){
            var start=i+name.length+1;
            var end=document.cookie.indexOf(";",i);
            if(end==-1){
                end=document.cookie.length;
            }
            val=document.cookie.substring(start,end);
        }
        //
        if(val!=undefined){
            document.cookie=name+"="+val+";expires="+new Date(0);
        }
    }

    //获取 用户名 cookie
   function getCookie(name) {
    var i = document.cookie.indexOf(name);
    if (i != -1) {
       var start = i + name.length + 1;
       var end = document.cookie.indexOf(";", i);
       if (end == -1) {
          end = document.cookie.length;
       }
       //
       return document.cookie.substring(start, end);
    }
 }
   
});
